--
-- Author: mm
-- Date: 2018-09-22 10:59:30
--
-- CorepropModel
--

local fileName = string.getModeName(...)
local ClassRef = class(fileName, app.mvc.ModelBase)

function ClassRef:ctor(data)
    self.super.ctor(self, data)
end

function ClassRef:init()

end

function ClassRef:getViewData()
    return {
        values = UD.coreProp:getValues(),
        leftPoint = UD.coreProp:getLeftPoint(),
        sumPoint = UD.coreProp:getSumPoint()
    }
end

------------------------ receive ------------------------


------------------------ request ------------------------

function ClassRef:reqGainCorePropPoint(num)
    app.session:request("pb_coreprop.C2S_GainCorePropPoint",{num = num}, function(ret, err)
        
        if err then
            display.pushToast(string.format("content: %s code : %s", err.content or "", err.code or ""))
            return
        end
        UD.coreProp:updateData(ret.data)
        UD.redPoint:checkStateByKey(RedPointConstant.CorePorp_Exchange)
        app:sendMsg( "CorePropController", "refreshView")
    end)
end

function ClassRef:reqAddOneCoreProp(tp, num)
    local tpString = protobuf.enum_name("pb_coreprop.PropType", tp)
    app.session:request("pb_coreprop.C2S_AddOneCoreProp",{corePropType = tpString, num = num}, function(ret, err)
        if err then
            display.pushToast(string.format("content: %s code : %s", err.content or "", err.code or ""))
            return
        end
        UD.coreProp:updateData(ret.data)
        UD.redPoint:checkStateByKey(RedPointConstant.CorePorp_Add)

        app:sendMsg( "CorePropController", "refreshView")
    end)
end

return ClassRef
